function getEnvironment() {
    const hostname = window.location.hostname;
    if (hostname === 'localhost' || hostname === '127.0.0.1') {
        return 'local';
    } else if (hostname.includes('test.')) {
        return 'test';
    } else {
        return 'production';
    }
}

function loadResource(src, type) {
    return new Promise((resolve, reject) => {
        let element;
        if (type === 'script') {
            element = document.createElement('script');
            element.type="text/javascript" ;
            element.src = src;
        } else if (type === 'stylesheet') {
            element = document.createElement('link');
            element.rel = 'stylesheet';
            element.href = src;
        }

        element.onload = resolve;
        element.onerror = reject;
        document.head.appendChild(element);
    });
}

// 使用示例
const currentEnvironment = getEnvironment();
console.log(`当前环境是：${currentEnvironment}`);

if (currentEnvironment === 'local') {

    loadResourcesFirst();
/*    Promise.all([
        loadResource('js/chart_js/jquery.min.js', 'script'),
        loadResource('css/font-awesome/css/font-awesome.min.css', 'stylesheet')
    ])
        .then(() => {
            console.log('所有资源加载完成');
            // 这里可以执行依赖这些资源的代码
        })
        .catch(error => {
            console.error('资源加载失败:', error);
        });*/
}
function loadResourcesFirst() {
    document.write(`
        <script src="js/chart_js/jquery.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
    `);
}